﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    /// <summary>
    /// API返回值结果Model
    /// </summary>
    public class APIResultModel
    {
        /// <summary>
        /// 0:成功
        /// 1:失败
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Msg { get; set; }

        /// <summary>
        /// 数据的数量
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 数据
        /// </summary>
        public object Data { get; set; }

        /// <summary>
        /// 获取成功结果
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static APIResultModel GetSuccessResult(string msg)
        {
            return new APIResultModel() { Code = 0, Msg = msg };
        }

        /// <summary>
        /// 获取成功结果
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static APIResultModel GetSuccessResult(string msg, object data)
        {
            return new APIResultModel() { Code = 0, Msg = msg, Data = data };
        }


        /// <summary>
        /// 获取Layui表格成功结果
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static APIResultModel GetSuccessResultForLayui(string msg, int count, object data)
        {
            return new APIResultModel() { Code = 0, Msg = msg, Data = data, Count = count };
        }

        /// <summary>
        /// 获取失败的结果
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static APIResultModel GetErrorResult(string msg)
        {
            return new APIResultModel() { Code = 1, Msg = msg };
        }

    }

}
